﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using smartphone.App_Code;

namespace smartphone.UserControls
{
    public partial class AdminEditNews : System.Web.UI.UserControl
    {
        private News news = new News();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Visible = false;
            if (!IsPostBack)
            {
                if (Request.QueryString["NewsID"] != null)
                {
                    this.Visible = true;
                    BindDetail();
                }
            }
        }


        /// <summary>
        /// Lay ma tin roi dua vao cac control tao san
        /// </summary>
        private void BindDetail()
        {
            string newsId = Request.QueryString["NewsID"];
            news = news.GetNewsDetail(Int32.Parse(newsId));
            TxtTitle.Text = news.Title;
            EditorContent.Content = news.Content;
            this.Visible = true;
        }

        protected void BtEditNews_Click(object sender, EventArgs e)
        {
            string newsId = Request.QueryString["NewsID"];
            string title = TxtTitle.Text;
            string content = EditorContent.Content;
            bool success = news.UpdateNews(Int32.Parse(newsId), title, content);

            Response.Redirect("AdminNews.aspx");
        }

        protected void BtEditNewsCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("AdminNews.aspx");
        }
    }
}